<?php
$name = $_REQUEST["name"];
$image = $_FILES["image"];
if($image["error"] == 0){
    // 以二进制的只读模式打开文件
    $file = fopen($image["tmp_name"], "rb");
    // 获取文件的大小
    $length = filesize($image["tmp_name"]);
    // 读取文件内容
    $content = fread($file, $length);
    $content = addslashes($content);
    // 用完后, 关闭文件(释放资源)
    fclose($file);

    // 保存到数据库
    $conn = mysqli_connect("localhost:3306","root","","php");
    $sql = "insert into t_product (p_name, p_image) values ('$name', '$content')";
    $result = mysqli_query($conn, $sql);
    if($result){
        echo "保存成功";
    } else {
        echo "保存失败:" . mysqli_error($conn);
    }
    mysqli_close($conn);
}
?>